import { createRouter, createWebHistory } from 'vue-router'
import { useTokenStore } from '@/stores'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
		{
			path: '/',
			name: 'login',
			component: () => import('@/views')
		},
		{
			path: '/home',
			name: 'home',
			component: () => import('@/views/home'),
			children: [
				{
					path: '/regist',
					name: 'regist',
					component: () => import('@/views/regist')
				},
				{
					path: '/pay/success',
					name: 'paySuccess',
					component: () => import('@/views/pay/success')
				},
				{
					path: '/regist/list',
					name: 'RegistList',
					component: () => import('@/views/regist/list')
				},
				{
					path: '/regist/payment',
					name: 'RegistPayment',
					component: () => import('@/views/regist/payment')
				},
				{
					path: '/doctor/records/list',
					name: 'RecordsList',
					component: () => import('@/views/doctor/records/list')
				},
				{
					path: '/doctor/records/add',
					name: 'RecordsAdd',
					component: () => import('@/views/doctor/records/add')
				},
				{
					path: '/chat',
					name: 'Chat',
					component: () => import('@/views/ai/chat')
				}
			]
		}
	]
})
router.beforeEach((to, from, next) => {
	const tokenStore = useTokenStore()
	const token = tokenStore.getToken()
	if (token || to.fullPath === '/') {
		next()
	} else {
		next('/')
	}
})
export default router
